#ifndef _DSWONVIFRECODER_H
#define _DSWONVIFRECODER_H

#include "base.h"

class CDswonvifrecoder
{
public:
	CDswonvifrecoder(LPST_ENV_T pEnv, char* pUUID, LPST_VIDEO_MEM_T pVideoMem, LPST_EXTERNAL_CAM_PROPERTY_T pProperty, ENM_HD_STATUS nHdStatus);
	virtual ~CDswonvifrecoder();
public:
	void ForceSave();
	void SetDiskStatus(ENM_HD_STATUS nStatus);
private:
	static void* cbRecThreadFunc(void* pParam){((CDswonvifrecoder*)pParam)->RecThreadFunc();return NULL;};
	void RecThreadFunc();

	bool PutFrameToRam(LPST_VIDEO_FRAME_T pFrame, int &nRamSize);
	bool PutRamToTmpFile(int &nRamSize);
	bool SaveTmpFileTo3gp(unsigned char* pSps, int nSpsLen, unsigned char* pPps, int nPpsLen, char* pFileName);

	static void* cbMake3GPThreadFunc(void* pParam){((CDswonvifrecoder*)pParam)->Make3GPThreadFunc();return NULL;};
	void Make3GPThreadFunc();

private:
	LPST_ENV_T m_pEnv;
	pthread_t m_thread_id, m_thread_make3gp;

	char m_sRecTmpFile[256];
	int m_nFps, m_nWidth, m_nHeight;

	pthread_mutex_t m_hd_lock;
	ENM_HD_STATUS m_hd_status;

	unsigned char m_nSps[512], m_nPps[512];
	int m_nSpsLen, m_nPpsLen;

	bool m_bForceSave;

	char m_sUUID[256];
	LPST_VIDEO_MEM_T m_pVideoMem;
	bool m_bStopRec;

	char* m_pRecBuffer;
	char* m_pRecBufPos;

	LIST_TMPFILENAME_T m_nTmpFileList;
	pthread_mutex_t m_nTmpFileListLock;

};

#endif

